<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="8" :lg="7" :md="8" :sm="24">
            <a-form-item label="免费聊天条数">
              <a-input-number placeholder="请输入免费聊天条数" style="width: 80%" v-model="FreeChat"></a-input-number> 条
            </a-form-item>
          </a-col>
          <a-col :xl="8" :lg="7" :md="8" :sm="24">
            <a-form-item label="视频速配收费标准(金币)/分钟">
              <a-input-number placeholder="请输入" style="width: 60%" v-model="VideoGear"></a-input-number> 金币/分钟
            </a-form-item>
          </a-col>
          <a-col :xl="2" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="submitForm">保存</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->
    <a-tabs default-active-key="1" @change="tabChange">
      <a-tab-pane key="1" tab="文字聊天">
      </a-tab-pane>
      <a-tab-pane key="2" tab="语音聊天">
      </a-tab-pane>
      <a-tab-pane key="3" tab="视频聊天">
      </a-tab-pane>
    </a-tabs>
    <!-- 操作按钮区域 -->
<!--    <div class="table-operator">
      <a-button @click="add" type="primary" icon="plus">{{btnText}}</a-button>
    </div>-->

    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text,record">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" :preview="record.id" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="edit(record)">修改</a>
<!--          <a-divider type="vertical" />
          <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
            <a>删除</a>
          </a-popconfirm>-->
        </span>

      </a-table>
    </div>

    <fee-settings-modal ref="modalForm" @ok="modalFormOk"></fee-settings-modal>
    <Fee-Item-List ref="FeeItemList"> </Fee-Item-List>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import FeeSettingsModal from './modules/FeeSettingsModal'
  import { httpAction, getAction } from '@/api/manage'
  import FeeItemList from './FeeItemList'
  import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'

  export default {
    name: 'FeeSettingsList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      FeeSettingsModal,
      FeeItemList
    },
    data () {
      return {
        description: '收费设置管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'聊天类型',
            align:"center",
            dataIndex: 'msgType_dictText'
          },
          /*{
            title:'价格(金币/条)',
            align:"center",
            dataIndex: 'price'
          },*/
          {
            title:'在线时长要求(小时)',
            align:"center",
            dataIndex: 'beginTime',
            customRender:function (t,r,index) {
              if(r.beginTime==0){
                  return "≤ "+r.endTime;
              }else if(r.endTime==9999999){
                  return "≥ "+r.beginTime;
              }else{
                return "> "+ r.beginTime+" 且 ≤"+r.endTime;
              }

            }
          },
          {
            title:'创建时间',
            align:"center",
            dataIndex: 'createTime'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/system/feeSettings/list",
          delete: "/system/feeSettings/delete",
          deleteBatch: "/system/feeSettings/deleteBatch",
          exportXlsUrl: "/system/feeSettings/exportXls",
          importExcelUrl: "system/feeSettings/importExcel",

        },
        dictOptions:{},
        superFieldList:[],

        disableMixinCreated:true,
        btnText:"添加文字聊天",
        clickType:"1",
        FreeChat:"",
        VideoGear:"",
      }
    },
    created() {
      this.initData();
      this.getSystemConfigMap();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      //初始化数据
      initData(){
        this.queryParam.msgType=this.clickType;
        this.loadData(1);
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'datetime',value:'createTime',text:'创建日期'})
        fieldList.push({type:'string',value:'msgType',text:'聊天类型（1-文字聊天 2-音视频聊天）',dictCode:'message_type'})
        fieldList.push({type:'string',value:'price',text:'价格(金币/条)',dictCode:''})
        fieldList.push({type:'string',value:'beginTime',text:'在线时长要求(最低时长)',dictCode:''})
        fieldList.push({type:'string',value:'endTime',text:'在线时长要求(最高时长)',dictCode:''})
        this.superFieldList = fieldList
      },

      //tab切换
      tabChange(key){
        this.clickType=key;
          if(key==1){
            this.btnText="添加文字聊天";
            this.columns[2].title="在线时长要求(小时)"
          }else if(key==2){
            this.btnText="添加语音聊天";
            this.columns[2].title="通话总时长要求(小时)"
          }else if(key==3){
            this.btnText="添加视频聊天";
            this.columns[2].title="通话总时长要求(小时)"
          }
        this.queryParam.msgType=this.clickType;
        this.loadData(1);
      },


      //修改界面
      edit(record) {
        this.$refs.FeeItemList.initData(record.id);
      },

      //获取回显数据
      getSystemConfigMap(){
        getAction('/system/systemConfig/getSystemConfigMap').then((res)=>{
          if(res.success){
            this.FreeChat=res.result.FreeChat;
            this.VideoGear=res.result.VideoGear;
          }
        })
      },
      //保存数据
      submitForm () {
        const that = this;
        // 触发表单验证
        if (!this.FreeChat) {
          this.$message.warning("请填写免费聊天条数");
          return;
        }
        if(!this.VideoGear){
          this.$message.warning("视频速配收费标准");
          return;
        }
        that.confirmLoading = true;
        let httpurl = '/system/systemConfig/saveOrUpdate';
        let method = 'post';
        let dataList=[];
        let obj={};
        obj.code="FreeChat";
        obj.value=this.FreeChat;
        obj.title="免费聊天条数";
        dataList.push(obj);
        obj={};
        obj.code="VideoGear";
        obj.value=this.VideoGear;
        obj.title="视频速配收费标准(金币)/分钟";
        dataList.push(obj)

        httpAction(httpurl,dataList,method).then((res)=>{
          if(res.success){
            that.$message.success(res.message);
            that.$emit('ok');
          }else{
            that.$message.warning(res.message);
          }
        }).finally(() => {
          that.confirmLoading = false;
        })
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>